﻿// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
IMessage message = new Message("Hello, World!");
IMessage encryptedMessage = new EncryptedMessage(message);
IMessage compressedAndEncryptedMessage = new CompressedMessage(encryptedMessage);

Console.WriteLine(compressedAndEncryptedMessage.GetContent());

// 假设我们有一个基本的文本消息类 Message，我们希望动态地为其添加加密和压缩功能。

// 基本组件接口
public interface IMessage
{
    string GetContent();
}

// 基本组件
public class Message : IMessage
{
    private readonly string _content;

    public Message(string content)
    {
        _content = content;
    }

    public string GetContent()
    {
        return _content;
    }
}

// 装饰器基类
public abstract class MessageDecorator : IMessage
{
    protected readonly IMessage _message;

    protected MessageDecorator(IMessage message)
    {
        _message = message;
    }

    public abstract string GetContent();
}

// 具体装饰器：加密
public class EncryptedMessage : MessageDecorator
{
    public EncryptedMessage(IMessage message) : base(message)
    {

    }    
    public override string GetContent()
    {
        return $"Encrypted({_message.GetContent()})";
    }
}


// 具体装饰器：压缩
public class CompressedMessage : MessageDecorator
{
    public CompressedMessage(IMessage message) : base(message) { }  
    public override string GetContent()
    {
        return $"Compressed({_message.GetContent()})";
    }
}